import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'
/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRoutes = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    hidden: false,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },

  // {
  //   path: '/cluster',
  //   component: Layout,
  //   redirect: '/cluster/list',
  //   name: 'Cluster',
  //   meta: { title: '集群管理', icon: 'cluster' },
  //   children: [
  //     {
  //       path: 'list',
  //       name: 'ClusterList',
  //       component: () => import('@/views/cluster/index'),
  //       meta: { title: '集群列表', icon: 'cluster' }
  //     },
  //     {
  //       path: 'nodes',
  //       name: 'ClusterNodes',
  //       component: () => import('@/views/cluster/ClusterDetail'),
  //       meta: { title: '节点', icon: 'cluster' },
  //       hidden: true
  //     }
  //   ]
  // },

  {
    path: '/task',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Task',
        component: () => import('@/views/task/index'),
        meta: { title: '任务列表', icon: 'form' }
      },
      {
        path: 'detail',
        name: 'TaskDetail',
        component: () => import('@/views/task/TaskView'),
        meta: { title: '任务详情', icon: 'form' },
        hidden: true,
        children: [
          {
            path: 'result',
            name: 'TaskDetailResult',
            component: () => import('@/views/task/TaskViewResult'),
            meta: { title: '任务结果', icon: 'form' },
            hidden: true
          },
          {
            path: 'chart',
            name: 'TaskDetailChart',
            component: () => import('@/views/task/TaskViewChart'),
            meta: { title: '图表', icon: 'form' },
            hidden: true
          },
          {
            path: 'config',
            name: 'TaskDetailConfig',
            component: () => import('@/views/task/TaskViewCfg'),
            meta: { title: '配置', icon: 'form' },
            hidden: true
          }
        ]
      }
    ]
  },

  // {
  //   path: '/user',
  //   component: Layout,
  //   redirect: '/user/plateform',
  //   name: 'User',
  //   meta: {
  //     title: '用户管理',
  //     icon: 'user'
  //   },
  //   children: [
  //     // {
  //     //   path: 'plateform',
  //     //   name: 'Plateform',
  //     //   component: () => import('@/views/user/plateform/index'),
  //     //   meta: { title: '平台用户管理' }
  //     // },
  //     {
  //       path: 'admin',
  //       name: 'Admin',
  //       component: () => import('@/views/user/admin/index'),
  //       meta: { title: '管理员管理' }
  //     }
  //   ]
  // },

  {
    path: '/machine',
    component: Layout,
    redirect: '/machine/unavailable',
    name: 'Machine',
    meta: {
      title: '机器管理',
      icon: 'machine'
    },
    children: [
      {
        path: 'baseinfo',
        name: 'Baseinfo',
        component: () => import('@/views/machine_manage/node_resource/index'),
        meta: { title: '资源使用情况' }
      }
      // {
      //   path: 'specification',
      //   name: 'Specification',
      //   component: () => import('@/views/machine_manage/specification/index'),
      //   meta: { title: '机器规格' }
      // }
      // {
      //   path: 'info',
      //   name: 'MachineInfo',
      //   component: () => import('@/views/machine_manage/machine_info/index'),
      //   meta: { title: '机器信息' }
      // },
      // {
      //   path: 'unavailable',
      //   name: 'Unavailable',
      //   component: () => import('@/views/machine_manage/unavailable/index'),
      //   meta: { title: '隔离资源' }
      // },
      // {
      //   path: 'logs',
      //   component: () => import('@/views/machine_manage/unavailable/logs'),
      //   name: 'UnavailableLogs',
      //   meta: { title: '隔离日志' },
      //   hidden: true
      // }
    ]
  },

  {
    path: '/source',
    component: Layout,
    redirect: '/source/image',
    name: 'Source',
    meta: {
      title: '配套资源',
      icon: 'image'
    },
    children: [
      {
        path: 'image',
        component: () => import('@/views/source/image/index'),
        name: 'Image',
        meta: { title: '官方镜像' }
      },
      {
        path: 'detail',
        component: () => import('@/views/source/detail'),
        name: 'Detail',
        meta: { title: '详情' },
        hidden: true
      }
    ]
  },

  {
    path: '/analysis',
    component: Layout,
    redirect: '/analysis/reboot',
    name: 'Analysis',
    meta: {
      title: '统计分析',
      icon: 'analysis'
    },
    children: [
      {
        path: 'reboot',
        component: () => import('@/views/analysis/node_reboot/index'),
        name: 'Reboot',
        meta: { title: '重启面板' }
      }
      // {
      //   path: 'zombies',
      //   component: () => import('@/views/analysis/container_zombies/index'),
      //   name: 'Zombies',
      //   meta: { title: '僵尸容器' }
      // }
    ]
  },

  // {
  //   path: '/license',
  //   component: Layout,
  //   children: [
  //     {
  //       path: 'index',
  //       name: 'License',
  //       component: () => import('@/views/license/index'),
  //       meta: { title: 'License', icon: 'license' }
  //     }
  //   ]
  // },

  {
    path: '/alarm',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Alarm',
        component: () => import('@/views/alarm/index'),
        meta: { title: '告警信息', icon: 'alarm' }
      }
    ]
  },

  {
    path: '/ticket',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'Ticket',
        component: () => import('@/views/ticket/index'),
        meta: { title: '工单管理', icon: 'ticket' }
      }
    ]
  },

  {
    path: 'external-config-link',
    component: Layout,
    children: [
      {
        path: '',
        meta: { title: '配置管理', icon: 'link' }
      }
    ]
  },

  {
    path: '/node',
    component: Layout,
    redirect: '/node/config',
    name: 'Node',
    meta: {
      title: '节点管理',
      icon: 'node'
    },
    children: [
      {
        path: 'config',
        name: 'NodeConfig',
        component: () => import('@/views/node/node_config.vue'),
        meta: { title: '节点配置', icon: 'node' }
      },
      {
        path: 'node',
        name: 'NodeList',
        component: () => import('@/views/node/node.vue'),
        meta: { title: '节点管理', icon: 'node' }
      }
    ]
  },

  {
    path: 'grafana',
    component: Layout,
    children: [
      {
        path: window.location.origin + '/grafana/d/db-cluster/clustermetrics?orgId=1&refresh=10s',
        meta: { title: '集群资源图表', icon: 'cluster' }
      }
    ]
  }
]
export default new Router({
  mode: 'history', // 后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

// 异步挂载的路由，动态需要根据权限加载的路由表
export const asyncRoutes = [
  {
    path: 'external-link',
    component: Layout,
    meta: { roles: ['admin'] },
    children: [
      {
        path: window.location.origin + '/sshlogin/',
        meta: { title: '节点登录', icon: 'link', roles: ['admin'] }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    redirect: '/user/plateform',
    name: 'User',
    meta: {
      title: '用户管理',
      icon: 'user',
      roles: ['super_admin']
    },
    children: [
      {
        path: 'admin',
        name: 'Admin',
        component: () => import('@/views/user/admin/index'),
        meta: { title: '管理员管理', roles: ['super_admin'] }
      }
    ]
  }
]
